package com.czkevin.cif.listeners;

import com.czkevin.cif.CIFItemInstance;
import com.czkevin.cif.CustomItemFramework;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;

public class CIFBlockDebuggerListener implements Listener {

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
    public void onTouch(PlayerInteractEvent event) {
        if(!CustomItemFramework.debug) return;
        if(event.getHand() != EquipmentSlot.HAND) return;
        Block block = event.getClickedBlock();
        if(block == null) return;
        CIFItemInstance instance = CustomItemFramework.getCIFDataFromBlock(block);
        if(instance == null) return;
        Player player = event.getPlayer();
        player.sendMessage(String.format("\u00a76Type: \u00a7d%s", instance.type.getClass().getSimpleName()));
        player.sendMessage(String.format("\u00a76Data: %s", instance.data == null ? "<null>" : instance.data.toString()));
    }

}
